
const until={
	setCookie(name,value){
		var Days = 3650; 
		var exp = new Date(); 
		exp.setTime(exp.getTime() + Days*24*60*60*1000); 
		document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
	},
	getCookie(name){ 
		console.log(name)
		var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		if(arr=document.cookie.match(reg))
			return unescape(arr[2]); 
		else 
			return null; 
	},
	delCookie(name){
		var exp = new Date(); 
		exp.setTime(exp.getTime() - 1); 
		var cval=this.getCookie(name); 
		if(cval!=null) 
			document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
	},
	getParameter(variable) {
		var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
      }
      return(false);
	},	  
	

	//格式化日期：yyyy-MM-dd
	formatDate(date) {
		date=new Date(date)
		var myyear = date.getFullYear();
		var mymonth = date.getMonth()+1;
		var myweekday = date.getDate();
		
		if(mymonth < 10){
			mymonth = "0" + mymonth;
		}
		if(myweekday < 10){
			myweekday = "0" + myweekday;
		}
		return (myyear+"-"+mymonth + "-" + myweekday);
	},
	

	formatDateHour(date) {
		date=new Date(date)
		var myyear = date.getFullYear();
		var mymonth = date.getMonth()+1;
		var myweekday = date.getDate();
		var myhour=date.getHours();
		let mymin=date.getMinutes();
		if(mymonth < 10){
			mymonth = "0" + mymonth;
		}
		if(myweekday < 10){
			myweekday = "0" + myweekday;
		}
		if(myhour<10){
			myhour="0"+myhour
		}
		if(mymin<10){
			mymin="0"+mymin
		}
		return (myyear+"-"+mymonth + "-" + myweekday+" "+myhour+":"+mymin);
	},
	formatNoyearDateHour(date) {
		date=new Date(date)
		var myyear = date.getFullYear();
		var mymonth = date.getMonth()+1;
		var myweekday = date.getDate();
		var myhour=date.getHours();
		let mymin=date.getMinutes();
		if(mymonth < 10){
			mymonth = "0" + mymonth;
		}
		if(myweekday < 10){
			myweekday = "0" + myweekday;
		}
		if(myhour<10){
			myhour="0"+myhour
		}
		if(mymin<10){
			mymin="0"+mymin
		}
		return (mymonth + "-" + myweekday+" "+myhour+":"+mymin);
	},
	dateHour(date) {
		date=new Date(date)
		var myyear = date.getFullYear();
		var mymonth = date.getMonth()+1;
		var myweekday = date.getDate();
		var myhour=date.getHours();
		let mymin=date.getMinutes();
		if(mymonth < 10){
			mymonth = "0" + mymonth;
		}
		if(myweekday < 10){
			myweekday = "0" + myweekday;
		}
		if(myhour<10){
			myhour="0"+myhour
		}
		if(mymin<10){
			mymin="0"+mymin
		}
		return (myhour+":"+mymin);
	},
	//计算两个时间之间的时间差 多少天时分秒
	
	
	
	getTimeNow(time) {
		let time_str = until.formatDateHour(time * 1000)
		var now = new Date();
		var date = new Date(time_str);
		let hour = date.getHours()
		let min = date.getMinutes()
		if (hour < 10) {
			hour = "0" + hour;
		}
		if (min < 10) {
			min = "0" + min;
		}
		//计算时间间隔，单位为分钟
		var inter = parseInt((now.getTime() - date.getTime()) / 1000 / 60);
		if (inter == 0) {
			return "刚刚";
		}
		//多少分钟前
		else if (inter < 60) {
			return inter.toString() + "分钟前";
		}
		//多少小时前
		else if (inter < 60 * 24) {
			return parseInt(inter / 60).toString() + "小时前";
		}
		//本年度内，日期不同，取日期+时间  格式如  06-13 22:11
		else if (now.getFullYear() == date.getFullYear()) {
			return (date.getMonth() + 1).toString() + "-" +
				date.getDate().toString() + " " +
				hour + ":" +
				min;
		}
		else {
			return date.getFullYear().toString().substring(0, 4) + "-" +
				(date.getMonth() + 1).toString() + "-" +
				date.getDate().toString() + " " +
				hour + ":" +
				min;
		}

	},

}
export default until;